package com.cls.business.service.impl;

import com.cls.common.entity.QueryRequest;
import com.cls.business.entity.BlackList;
import com.cls.business.mapper.BlackListMapper;
import com.cls.business.service.IBlackListService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;
import com.github.pagehelper.PageHelper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Arrays;
import java.util.List;

/**
 * 黑名单 Service实现
 *
 * @author slx
 * @date 2020-11-23 14:56:14
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class BlackListServiceImpl extends ServiceImpl<BlackListMapper, BlackList> implements IBlackListService {

    @Override
    public PageInfo<BlackList> findBlackLists(QueryRequest request, BlackList blackList) {
        LambdaQueryWrapper<BlackList> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<BlackList> list= this.list(queryWrapper);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }
    @Override
    public PageInfo<BlackList> findBlackListsPage(QueryRequest request, BlackList blackList) {

        // TODO 设置查询条件
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<BlackList> list= this.baseMapper.findBlackListsPage(blackList);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }
    @Override
    public BlackList getForId(Long blackListId) {
        return  this.baseMapper.getForId(blackListId);
    }

    @Override
    public List<BlackList> findBlackLists(BlackList blackList) {
	    LambdaQueryWrapper<BlackList> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
        if(StringUtils.isNotBlank(blackList.getIdentity())){
            queryWrapper.eq(BlackList::getIdentity,blackList.getIdentity());
        }
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createBlackList(BlackList blackList) {
        this.save(blackList);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateBlackList(BlackList blackList) {
        this.saveOrUpdate(blackList);
    }


    /**
    * 删除
    * @param ids
    */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteBlackLists(String[] ids) {
        List< String > list = Arrays.asList(ids);
        this.removeByIds(list);
     }

    @Override
    public BlackList findByIdentity(String identity){
        return baseMapper.findByIdentity(identity);
    }



}
